package Method;
import Book.Book;
import Book.BookList;

import java.util.Scanner;

//增加图书
public class Addoperation implements IOperation  {
    @Override
    public void work(BookList bookList){
        System.out.println("增加图书：");
        Scanner sc =new Scanner(System.in);
        System.out.println("请输入图书id：");
        String id = sc.nextLine();
        System.out.println("请输入书名：");
        String name =sc.nextLine();
        System.out.println("请输入作者：");
        String author =sc.nextLine();
        System.out.println("请输入出版社：");
        String press =sc.nextLine();
        System.out.println("请输入价格：");
        int price =sc.nextInt();

        Book newbook = new Book(id,name,author,price,press);
        int tmp=bookList.getBooksNum();

        for (int i = 0; i < tmp; i++) {
            if(bookList.getBook(i).getId().equals(id)){
                System.out.println("该编号已对应图书，不可重复添加！");
                return ;
            }

        }

        bookList.setBook(newbook,tmp);
        bookList.setBooksNum(tmp+1);
    }
}
